package com.example.repository;

import com.example.model.Question;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface QuestionRepository extends JpaRepository<Question, Long> {
    @Query("SELECT q FROM Question q WHERE q.keywords LIKE %:keyword%")
    List<Question> findByKeywords(@Param("keyword") String keyword);
    
    List<Question> findByIsCollectedTrue();
    
    @Query("SELECT q FROM Question q WHERE q.isLearned = true")
    List<Question> findByIsLearnedTrue();
    
    @Query("SELECT q FROM Question q WHERE q.keywords LIKE %:topic%")
    List<Question> findByTopic(@Param("topic") String topic);

    List<Question> findByQuestionContainingOrAnswerContaining(String question, String answer);
    
    long countByIsLearnedTrue();
    
    long countByIsCollectedTrue();
    
    @Query("SELECT COALESCE(AVG(q.difficulty), 0.0) FROM Question q")
    Double getAverageDifficulty();
    
    @Query("SELECT q.keywords FROM Question q")
    List<String> findAllKeywords();

    List<Question> findAllByOrderByCreateTimeDesc();

    List<Question> findByCreateTimeBetweenOrderByCreateTimeDesc(
        LocalDateTime start, 
        LocalDateTime end
    );
} 